//*************************************************************************************
//* 作    者： zouhunter
//* 创建时间： 2021-10-07 10:05:05
//* 描    述： 选中音效
//             点击音效

//* ************************************************************************************
using UnityEngine;
using UnityEngine.EventSystems;

public class SelectableAudioBehaviour : MonoBehaviour
{
    [UnityEngine.Serialization.FormerlySerializedAs("m_hoverAudioId")]
    public int hoverAudioId;
    [UnityEngine.Serialization.FormerlySerializedAs("m_clickAudioId")]
    public int clickAudioId;

    private void Awake()
    {
        var hoverEntry = new EventTrigger.Entry();
        hoverEntry.eventID = EventTriggerType.PointerEnter;
        hoverEntry.callback.AddListener(OnHoverEnter);

        var clickEntry = new EventTrigger.Entry();
        clickEntry.eventID = EventTriggerType.PointerClick;
        clickEntry.callback.AddListener(OnClick);

        var eventTrigger = gameObject.MustComponent<EventTrigger>();
        eventTrigger.triggers.Add(hoverEntry);
        eventTrigger.triggers.Add(clickEntry);
    }

    private void OnHoverEnter(BaseEventData arg0)
    {
        SoundAgent.PlayAudioById(hoverAudioId);
    }

    private void OnClick(BaseEventData arg0)
    {
        SoundAgent.PlayAudioById(clickAudioId);
    }
}
